package jehc.djshi.sys.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jehc.djshi.common.annotation.Auth;
import jehc.djshi.common.base.*;
import jehc.djshi.common.entity.OauthAccountEntity;
import jehc.djshi.common.util.StringUtil;
import jehc.djshi.sys.model.XtEncoderQrcode;
import jehc.djshi.sys.service.XtEncoderQrcodeService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
/**
 * @Desc 平台二维码
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/xtEncoderqrcode")
@Api(value = "平台二维码API",tags = "平台二维码API",description = "平台二维码API")
public class XtEncoderQrcodeController extends BaseAction {

	@Resource
	private XtEncoderQrcodeService xtEncoderqrcodeService;

	/**
	 * 查询平台二维码列表并分页
	 * @param baseSearch
	 */
	@PostMapping(value="/list")
	@Auth(value = "/xtEncoderqrcode/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@ApiOperation(value="查询平台二维码列表并分页", notes="查询平台二维码列表并分页")
	public BasePage<List<XtEncoderQrcode>> getXtEncoderQrcodeListByCondition(@RequestBody(required=true)BaseSearch baseSearch){
		Map<String, Object> condition = baseSearch.convert();
		commonHPager(baseSearch);
		List<XtEncoderQrcode> xtEncoderQrcodeList = xtEncoderqrcodeService.getXtEncoderQrcodeListByCondition(condition);
		for(XtEncoderQrcode xtEncoderQrcode : xtEncoderQrcodeList){
			if(!StringUtil.isEmpty(xtEncoderQrcode.getCreateId())){
				OauthAccountEntity createBy = getAccount(xtEncoderQrcode.getCreateId());
				if(null != createBy){
					xtEncoderQrcode.setCreateBy(createBy.getName());
				}
			}
			if(!StringUtil.isEmpty(xtEncoderQrcode.getUpdateId())){
				OauthAccountEntity modifiedBy = getAccount(xtEncoderQrcode.getUpdateId());
				if(null != modifiedBy){
					xtEncoderQrcode.setModifiedBy(modifiedBy.getName());
				}
			}
		}
		PageInfo<XtEncoderQrcode> page = new PageInfo<XtEncoderQrcode>(xtEncoderQrcodeList);
		return outPageBootStr(page,baseSearch);
	}

	/**
	 * 查询单个平台二维码
	 * @param id
	 */
	@GetMapping(value="/get/{id}")
	@Auth(value = "/xtEncoderqrcode/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@ApiOperation(value="查询单个平台二维码", notes="查询单个平台二维码")
	public BaseResult<XtEncoderQrcode> getXtEncoderQrcodeById(@PathVariable("id")String id){
		XtEncoderQrcode xtEncoderQrcode = xtEncoderqrcodeService.getXtEncoderQrcodeById(id);
		if(!StringUtil.isEmpty(xtEncoderQrcode.getCreateId())){
			OauthAccountEntity createBy = getAccount(xtEncoderQrcode.getCreateId());
			if(null != createBy){
				xtEncoderQrcode.setCreateBy(createBy.getName());
			}
		}
		if(!StringUtil.isEmpty(xtEncoderQrcode.getUpdateId())){
			OauthAccountEntity modifiedBy = getAccount(xtEncoderQrcode.getUpdateId());
			if(null != modifiedBy){
				xtEncoderQrcode.setModifiedBy(modifiedBy.getName());
			}
		}
		return outDataStr(xtEncoderQrcode);
	}

	/**
	 * 添加
	 * @param xtEncoderqrcode
	 */
	@PostMapping(value="/add")
	@ApiOperation(value="创建单个平台二维码", notes="创建单个平台二维码")
	public BaseResult addXtEncoderQrcode(@RequestBody XtEncoderQrcode xtEncoderqrcode){
		int i = 0;
		if(null != xtEncoderqrcode){
			xtEncoderqrcode.setId(toUUID());
			i=xtEncoderqrcodeService.addXtEncoderQrcode(xtEncoderqrcode);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 修改
	 * @param xtEncoderqrcode
	 */
	@PutMapping(value="/update")
	@ApiOperation(value="编辑单个平台二维码", notes="编辑单个平台二维码")
	public BaseResult updateXtEncoderQrcode(@RequestBody XtEncoderQrcode xtEncoderqrcode){
		int i = 0;
		if(null != xtEncoderqrcode){
			i=xtEncoderqrcodeService.updateXtEncoderQrcode(xtEncoderqrcode);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 删除
	 * @param id
	 */
	@DeleteMapping(value="/delete")
	@ApiOperation(value="删除平台二维码", notes="删除平台二维码")
	public BaseResult delXtEncoderQrcode(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i=xtEncoderqrcodeService.delXtEncoderQrcode(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}
